﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VideoNetApplication.Common.Web;

namespace VideoNetApplication.Common.Dao
{
   public class CommentDao
    {
        public  int AddComment(V_VideoComment comment)
        {
            using (EVDBEntities edm = new EVDBEntities())
            {
                var query = new V_VideoComment();
                query.CourseListId = comment.CourseListId;
                query.CommentUserName = comment.CommentUserName;
                query.CommentContent = comment.CommentContent;
                query.CreatedTime = comment.CreatedTime;
                query.CommentUserId = comment.CommentUserId;
                edm.AddToV_VideoComment(query);
                if (edm.SaveChanges() >= 1)
                {
                    return 1;
                }
                return -1;

            }
        }

        public int GetMessageCnt(int courseId)
        {
            using (EVDBEntities nis = new EVDBEntities())
            {
                return nis.V_VideoComment.Where(s => s.CourseListId == courseId).Count();
            }

        }
        public List<V_VideoComment> GetMessageList(int courseId, int startRowIndex, int maximumRows)
        {
            using (EVDBEntities entities = new EVDBEntities())
            {
                return
                    entities.V_VideoComment.Where(s => s.CourseListId == courseId).OrderByDescending(s => s.ID).Skip(startRowIndex)
                        .Take(maximumRows).ToList();
            }
        }
    }
}
